<template>
    <div class="app-container ">
        <el-row ref="refbut">
            <el-col :span="24" style="">
                <el-card class="box-card">
                    <el-form>
                        <el-form-item label="任务名称">
                            <el-select v-model="nameId" placeholder="请选择任务名称" style="width:300px" @change="selectChange">
                                <el-option v-for='item in selectlist' :key="item.ID" :label="item.JIANDINGRENWUNAME"
                                    :value="item.ID"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>
                    <el-row>
                        <el-col :span="12"> <el-descriptions title="" :column="4">
                                <el-descriptions-item label="任务总数">{{ numInfo.ALLNUM }}</el-descriptions-item>
                                <el-descriptions-item label="个人分配数">{{ numInfo.NOWPERSON }}</el-descriptions-item>
                                <el-descriptions-item label="待审核数">{{ numInfo.NOWPERSON - numInfo.HADSH
                                }}</el-descriptions-item>
                                <!-- <el-descriptions-item style="display: none;"></el-descriptions-item>
                                <el-descriptions-item label="开放档案数">0</el-descriptions-item>
                                <el-descriptions-item label="原文抽查需大于等于">0</el-descriptions-item>
                                <el-descriptions-item label="原文已抽查">0</el-descriptions-item>
                                <el-descriptions-item label="开放档案审查进度">0</el-descriptions-item>
                                <el-descriptions-item label="控制档案数">0</el-descriptions-item>
                                <el-descriptions-item label="原文抽查需大于等于">0</el-descriptions-item>
                                <el-descriptions-item label="原文已抽查">0</el-descriptions-item>
                                <el-descriptions-item label="控制档案审查进度">0</el-descriptions-item> -->

                            </el-descriptions></el-col>
                    </el-row>

                </el-card>

                <el-row>
                    <el-col :span="24" style="margin-top:20px">
                        <el-form ref="queryForm" :inline="true" v-show="showSearch">
                            <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                                <span slot="label">{{ item.FIELD_CAPTION }} </span>
                                <input_item :item="item" @onChangeTap="onChangeTap" :inputType="1"
                                    :inputParams="queryParams">
                                </input_item>
                            </el-form-item>
                            <el-form-item label="初审结果">
                                <el-select placeholder="请选择" v-model="listQueryParams.chushenresult">
                                    <el-option v-for="item in dict.type.MJ" :key="item.value" :label="item.label"
                                        :value="item.value"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="复审状态">
                                <el-select v-model="listQueryParams.jdstate" placeholder="请选择">
                                    <el-option label="未审核" value="0"></el-option>
                                    <el-option label="已审核" value="1"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item>
                                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                            </el-form-item>
                        </el-form>
                    </el-col>
                    <el-col :span="24">
                        <el-divider></el-divider>
                    </el-col>
                </el-row>

                <el-row :gutter="10" class="mb8">
                    <!-- <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="offTap">批量开放</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="onTap">批量控制</el-button>
                    </el-col> -->
                    <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-plus" @click="submitTap">提交</el-button>
                    </el-col>
                </el-row>
            </el-col>
        </el-row>
        <tableList :tableHeaderList="tableHeaderList" :tableData="tableData" :loading="loading" :tableHeight="tableHeight"
            @sortChange="sortChange" :isFuSHen="true" @onBlurDeitTap="onBlurDeitTap"
            @handleSelectionChange="handleSelectionChange" :isSelection="isSelection" @shengchaclick="shengchaclick"
            :iskfjdorbgqx="iskfjdorbgqx" ref="ref">
        </tableList>
        <pagination v-show="total > 0" :total="total" :page.sync="listQueryParams.pageNum"
            :limit.sync="listQueryParams.pageSize" @pagination="fssplistPOST" />
        <!--start  组件详情 -->
        <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose" @onBlurDeitTap="onBlurDeitTap">
        </jianDetailsOpen>
        <!--end 组件详情 -->
        <!-- start 组卷\项目详情 -->
        <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose" @onBlurDeitTap="onBlurDeitTap" :chuFushenParams="chuFushenParams">
        </juanDetailsOpen>
        <!-- end 组卷\项目详情 -->


    </div>
</template>
<script>
import { getfushennum, getfushenjob, fssplist, choucha3 } from "@/api/archive/archivalAppraisal/classificationIdentify/openArchivesFuShen"
import { chushentijiao, mj_updateshending, mj_updateliyou, mj_updatebeizhu } from "@/api/archive/archivalAppraisal/classificationIdentify/openArchivesAppraisal"
import { getqueryfieldList, getshowfield } from "@/api/archive/fileCollection/offlinReception"
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import { getInfo } from "@/api/login.js"
import input_item from "@/components/input/index.vue"
import estimateTableHeight from '@/mixins/estimateTableHeight';
import tableList from "@/components/tableList/index.vue"
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
export default {
    archive_Dicts: ['IS_OPENS', 'BGQX', 'MJ'],
    mixins: [estimateTableHeight], // 混入方法
    components: {
        input_item,
        tableList,
        jianDetailsOpen,
        juanDetailsOpen
    },
    data() {
        return {
            // iskfjdorbgqx="0"  开放鉴定   :iskfjdorbgqx="1" 保管期限   :iskfjdorbgqx="2" 销毁鉴定  :iskfjdorbgqx="3" 密级鉴定
            iskfjdorbgqx: "3",
            loading: false,
            listFrom: [], //查询框列表
            showSearch: true,// 显示搜索条件
            queryParams: {},
            listQueryParams: {
                searchcolumn: undefined,//查询参数
                pageNum: 1,
                pageSize: 10,
                order: undefined,
                jdstate: undefined,
                chushenresult: undefined,//初审结果
                fields: undefined,
                ids: undefined,
            },
            nameId: "",
            selectlist: "",
            numInfo: { //获取任务总数
                "NOWPERSON": 0, //当前人分配数
                "HADSH": 0,   //已审核数
                "ALLNUM": 0,  //总数
                "PERCENTAGE": "0%",//占比
            },
            rowNameIDrow: "", //当前下拉数据
            tableHeaderList: [],
            tableData: [],
            total: 0,
            single: true,
            multiple: true,
            isSelection: false,
            jianDetailsOpen: false,
            juanDetailsOpen: false,
            rowInfo: "",
            chuFushenParams: ""
        }
    },
    created() {

        this.getfushenjobPOST();

    },
    methods: {

        // 获取当前人复审任务
        getfushenjobPOST() {
            getfushenjob().then(res => {
                if (res.code == "200") {
                    this.selectlist = res.data;
                    if (res.data.length > 0) {
                        this.rowNameIDrow = res.data[0];
                        this.nameId = res.data[0].ID
                        this.listQueryParams.renwuid = this.rowNameIDrow.ID
                        this.getInfoPOST(); //获取当前用户的ID 根据ID获取任务总数/当前人分配数/待审核数/占比
                        this.getGroupTreePost(); //档案门类树门类详情，根据详情获取查询列表
                        this.getshowfieldPost() //列表
                        // this.getchouchanumPOST();
                    } else {
                        this.rowNameIDrow = "";
                        this.nameId = ""
                        this.listQueryParams.renwuid = undefined
                        this.tableHeaderList = [];
                        this.tableData = [];
                        this.numInfo = { //获取任务总数
                            "NOWPERSON": 0, //当前人分配数
                            "HADSH": 0,   //已审核数
                            "ALLNUM": 0,  //总数
                            "PERCENTAGE": "0%",//占比
                        }
                    }
                }
            })
        },
        //下拉事件
        selectChange() {
            this.queryParams = {};
            var rowNameIDrow = this.selectlist.filter(res => {
                return res.ID == this.nameId
            })
            this.rowNameIDrow = rowNameIDrow[0];
            this.listQueryParams.renwuid = this.rowNameIDrow.ID;
            this.listQueryParams.pageNum = 1;
            this.listQueryParams.pageSize = 10;
            this.listQueryParams.searchcolumn = undefined;
            this.listQueryParams.jdstate = undefined;
            this.listQueryParams.chushenresult = undefined;
            this.listQueryParams.order = undefined;
            this.getInfoPOST(); //获取当前用户的ID 根据ID获取任务总数/当前人分配数/待审核数/占比
            this.getGroupTreePost(); //档案门类树门类详情，根据详情获取查询列表
            this.getshowfieldPost() //列表
        },

        //获取当前用户的ID
        getInfoPOST() {
            getInfo().then(res => {
                this.getfushennumPOST(res.user.userId);
            })
        },
        //获取任务总数/当前人分配数/待审核数/占比
        getfushennumPOST(userId) {
            getfushennum(this.nameId, userId).then(res => {
                this.numInfo = res.data;
            })
        },

        //档案门类树门类根据categoryID回显 /** 获取查询字段 */
        getGroupTreePost() {
            getGroupTree(this.rowNameIDrow.CATEGORYID).then(response => {
                var SUB_TABLE_NAME = ""
                if (this.rowNameIDrow.TYPE == "f") {//件
                    SUB_TABLE_NAME = response.data.fileTableName;
                } else if (this.rowNameIDrow.TYPE == "v") { //卷
                    SUB_TABLE_NAME = response.data.folderTableName;
                } else {//项目
                    SUB_TABLE_NAME = response.data.itemTableName;
                }
                this.listQueryParams.subTableName = SUB_TABLE_NAME
                /** 获取查询字段 */
                getqueryfieldList({
                    categoryId: this.rowNameIDrow.CATEGORYID,
                    menuId: this.$route.meta.menuId,
                    subTableName: SUB_TABLE_NAME
                }).then(response => {
                    this.listFrom = response.rows;
                });
            });
        },

        closeDelDialog() {
            this.$emit("closeDelDialog")
        },

        onChangeTap(data) {
            var dataArr=""
            if(data.val!=undefined){
              dataArr = data.queryParams;
            }else{
              dataArr = data;
            }
            if (this.queryParams.length > 0) {
                for (var i in this.queryParams) {
                    if (Object.keys(this.queryParams[i]).toString() == Object.keys(data).toString()) {
                        this.queryParams.splice(i, 1)
                    }
                }
                this.queryParams = dataArr;
            } else {
                this.queryParams = dataArr;
            }

        },
        handleQuery() {
            var searchcolumn = []
            for (var k in this.listFrom) {
                for (var i in this.queryParams) {
                  if (this.queryParams[i] != null) {
                    if (this.listFrom[k].FIELD_NAME == i) {
                      if (this.listFrom[k].SHOWTYPE == 3 && this.listFrom[k].IS_QUERY == 4) {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME,
                          "value": this.queryParams[i][0],
                          "valueTwo": this.queryParams[i][1],
                        })
                      } else if (this.listFrom[k].SHOWTYPE == 7 || this.listFrom[k].SHOWTYPE == 8) {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME + "_ID",
                          "value": this.queryParams[i + "_ID"],

                        })
                      } else {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME,
                          "value": this.queryParams[i],

                        })
                      }
                    }
                  }
                }
            }

            this.listQueryParams.searchcolumn = searchcolumn;
            this.listQueryParams.order = undefined;
            this.fssplistPOST();
            this.$refs.ref.clearSort()
        },


        //重置
        resetQuery() {
            this.queryParams = {};
            this.listQueryParams.jdstate = undefined;
            this.listQueryParams.chushenresult = undefined;
            this.listQueryParams.searchcolumn = undefined;
            this.listQueryParams.order = undefined;
            this.fssplistPOST();
            this.$refs.ref.clearSort()
        },
        //排序
        sortChange(val) {
            this.listQueryParams.order = val;
            this.fssplistPOST();
        },

        //获取表头列表
        getshowfieldPost() {
            var level = "";
            if (this.rowNameIDrow.TYPE == "f") {//件
                level = "jian"
            } else if (this.rowNameIDrow.TYPE == "v") { //卷
                level = "juan"
            } else {//项目
                level = "xiangmu"
            }
            var fields = [];
            this.loading = true;
            getshowfield({
                level: level,
                categoryId: this.rowNameIDrow.CATEGORYID,
                menuId: this.$route.meta.menuId,
            }).then(res => {
                this.tableHeaderList = res.data;
                for (var i in res.data) {
                    fields.push(res.data[i].FIELD_NAME)
                }
                this.listQueryParams.fields = fields.toString();
                this.fssplistPOST()
            })
        },

        //列表展示
        fssplistPOST() {
          if (this.listQueryParams.renwuid != undefined) {
            fssplist(this.listQueryParams).then(res => {
              this.tableData = res.rows;
              this.total = res.total;
              this.loading = false;
            })
          }
        },
        //多选框选中数据
        handleSelectionChange(ids, single, multiple, selection) {
            console.log(ids, single, multiple, selection)
            this.ids = ids;
            this.single = single;
            this.multiple = multiple;
        },

        //提交
        submitTap() {
          if (this.listQueryParams.renwuid == undefined) {
            this.$message({ message: '请选择任务名称', type: 'warning' })
            return false
          } else {
            if (this.multiple) {
              this.$message({message: '请选择要提交的数据哦', type: 'warning'})
              return false
            } else {
              chushentijiao({
                renwuid: this.listQueryParams.renwuid,
                daids: this.ids,
                type: "fushen"
              }).then(res => {
                if (res.code == "200") {
                  this.$modal.msgSuccess(res.msg);

                  this.getfushenjobPOST()
                }
              })
            }
          }
        },

        offTap() {
            if (this.multiple) {
                this.$message({ message: '请选择要提交的数据哦', type: 'warning' })
                return false
            } else {
                mj_updateshending({
                    type: "chushen",
                    level: this.rowNameIDrow.type,
                    renwuid: this.listQueryParams.renwuid,
                    daid: this.ids,
                    jdvalue: 0,
                }).then(res => {

                })

            }
        },
        onTap() {
            if (this.multiple) {
                this.$message({ message: '请选择要提交的数据哦', type: 'warning' })
                return false
            } else {
                mj_updateshending({
                    type: "chushen",
                    level: this.rowNameIDrow.type,
                    renwuid: this.listQueryParams.renwuid,
                    daid: this.ids,
                    jdvalue: 1,
                }).then(res => {

                })

            }
        },

        //onBlurDeitTap
        //初审鉴定下拉修改
        onBlurDeitTap(data, type, FUSHEN_JIANDING) {
            console.log(type)
            if (type == 1) {  //初审鉴定
                var daid = "";
                var jdvalue = "";
                var level = "";
                if (data != "") {
                    daid = data.ID;
                    jdvalue = data.FUSHEN_JIANDING,
                        level = data.CATETYPE
                } else {
                    daid = this.rowInfo.ID;
                    jdvalue = FUSHEN_JIANDING
                    level = this.rowInfo.CATETYPE
                }
                // if (jdvalue == 1) {
                //     mj_updateliyou({
                //         type: "fushen",
                //         level: level,
                //         renwuid: this.listQueryParams.renwuid,
                //         daid: daid,
                //         lyvalue: "",
                //     }).then(res => {
                //
                //     })
                // }
                mj_updateshending({
                    type: "fushen",
                    level: level,
                    renwuid: this.listQueryParams.renwuid,
                    daid: daid,
                    jdvalue: jdvalue,
                }).then(res => {
                    this.$message({ message: res.msg, type: 'warning' })
                })
                this.jianDetailsOpen = false;
                this.juanDetailsOpen = false;

                this.fssplistPOST();
                this.getInfoPOST();
            } else if (type == 2) { //初审控制理由
                // mj_updateliyou({
                //     type: "fushen",
                //     level: level,
                //     renwuid: this.listQueryParams.renwuid,
                //     daid: data.ID,
                //     lyvalue: data.FUSHEN_LIYOU,
                //
                // }).then(res => {
                //
                // })
            } else { //备注

                mj_updatebeizhu({
                    type: "fushen",
                    level: level,
                    renwuid: this.listQueryParams.renwuid,
                    daid: data.ID,
                    beizhu: data.FUSHEN_BEIZHU
                }).then(res => {

                })
            }


        },


        //点击审查列表进入详情页面
        shengchaclick(row) {
            console.log(row, "sldkfjl")
            this.rowInfo = row;
            var level = "";
            if (this.rowNameIDrow.TYPE == "f") {  //F 件
                level = 0
            } else if (this.rowNameIDrow.TYPE == "v") { //卷
                level = 1
            } else { //项目
                level = 3

            }
            this.celldbData = {
                id: row.ID,
                categoryId: this.rowNameIDrow.CATEGORYID,
                menuId: this.$route.meta.menuId,
                sub_table_name: this.listQueryParams.subTableName,
                label: row.TITLE ? row.TITLE : '暂无标题',
                level: level,
                ifSub_table_name: this.listQueryParams.subTableName,
                isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                NEWTITLE: row.NEWTITLE,
                JIANDING: row.FUSHEN_JIANDING,
                tableHeaderList: this.tableHeaderList
            }

            this.$nextTick(() => {
                if (this.rowNameIDrow.TYPE == "f") {  //F 进入件详情
                    choucha3({
                        daid: row.ID,
                        renwuid: this.listQueryParams.renwuid,
                        type: this.rowNameIDrow.TYPE
                    }).then(res => {
                        console.log(res)
                    })
                    this.jianDetailsOpen = true;
                } else { //进入卷详情 和项目详情
                    choucha3({
                      daid: row.ID,
                      renwuid: this.listQueryParams.renwuid,
                      type: this.rowNameIDrow.TYPE
                    }).then(res => {
                      console.log(res)
                    })
                    this.chuFushenParams = {
                        renwuid: this.listQueryParams.renwuid,
                        daid: row.ID,
                        level: row.CATETYPE,
                        isFuSHen: true,
                        type: "fushen",
                        isSelection: false,
                        iskfjdorbgqx: "3"  //:iskfjdorbgqx="0"  开放鉴定   :iskfjdorbgqx="1" 保管期限
                    }
                    this.juanDetailsOpen = true
                }
            })

        },








        //关闭详情页面
        detailsHandleClose() {
            this.jianDetailsOpen = false;
            this.juanDetailsOpen = false;
        },



    }
}
</script>
<style lang="scss" scoped>
.el-divider {
    margin-top: 0;
}
</style>
